/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file workerdiscoveryproxy.h
 * @author Marco Buzzanca
 *
 * This file contains WorkerDiscoveryProxy class declaration.
 */

#ifndef _WORKER_DISCOVERY_PROXY_H_
#define _WORKER_DISCOVERY_PROXY_H_ 1

#include <boost/cstdint.hpp>
#include <string>

#include "workerdescriptor.h"
#include "udpclient.h"
#include "taskdescriptor.h"
#include "address.h"

/**
 * WorkerDiscoveryProxy
 *
 * Proxy which allows remote access to the workers' collection of the
 * discovery node.
 */
class WorkerDiscoveryProxy
{
private:
    /**
     * @brief It will behave as a client, so we need an UDPClient object.
     */
    UDPClient _client;

public:
    /**
     * @brief Default constructor.
     */
    WorkerDiscoveryProxy();

    /**
     * @brief Configures client with specified IP and port.
     * @param IP The provided IP address.
     * @param port The provided port.
     */
    WorkerDiscoveryProxy(const std::string& IP, boost::uint16_t port);

    /**
     * @brief Configures client with specified address.
     * @param address The provided address.
     */
    WorkerDiscoveryProxy(const Address& address);

    /**
     * @brief Destructor.
     */
    ~WorkerDiscoveryProxy();

    /**
     * @brief Gets address of the discovery node.
     * @return Discovery address.
     */
    const Address& getAddr() const;

    /**
     * @brief Sets address of the discovery node using provided IP and port.
     * @param IP The provided IP address.
     * @param port The provided port.
     */
    void setAddr(const std::string& IP, boost::uint16_t port);

    /**
     * @brief Sets address of the discovery node using provided address.
     * @param address The provided address.
     */
    void setAddr(const Address& address);

    /**
     * @brief Asks the discovery node for the address of a worker capable of
     *        handling provided TaskDescriptor.
     * @param td The provided TaskDescriptor.
     * @return The Address of the worker found according to search criteria.
     */
    Address getWorker(const TaskDescriptor& td);

    /**
     * @brief Asks the discovery node to add provided worker to the workers
     *        container.
     * @param wd The provided WorkerDescriptor.
     */
    void addWorker(const WorkerDescriptor& wd);

    /**
     * @brief Asks the discovery node to replace WorkerDescriptor at 
     *        provided index with new content.
     * @param index The provided index.
     * @param wd    The provided WorkerDescriptor.
     */
    void updateWorker(size_t index, const WorkerDescriptor& wd);

};

#endif /* _WORKER_DISCOVERY_PROXY_H_ */
